import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import remfont from './util/font-rem';
import 'element-ui/lib/theme-chalk/index.css';

Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(remfont);


router.beforeEach((to, from, next) => {
  let userobj = JSON.parse(localStorage.getItem('userlist'));
  let lsList = store.state.userStore.userList
  let flag = true;
  console.log(lsList, userobj);
  if (userobj == null || userobj == undefined || userobj == {}) {
    userobj = {
      password: '',
      user: ''
    }
  }
  let userpassword =  lsList.filter((item) => {
    return item.user === userobj.user
  })[0];
  if (to.fullPath == '/login' || to.fullPath == "/register") {
    next()
  } else {
    if (userpassword) {
      // console.log(userpassword,userobj.password);
      if (userpassword.password == userobj.password) {
        next()
      } else {
        next('/login')
      }
    } else {
      next('/login')
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
